import { getUserInfo } from '@/api/login'
import { makeObservable, action, observable } from 'mobx'
class User {
  constructor() {
    makeObservable(this, {
      userInfo: observable,
      getInfo: action.bound,
      delInfo: action.bound
    })
  }
  userInfo = localStorage.getItem('react-info') || {}

  async getInfo() {
    const res = await getUserInfo()
    this.userInfo = res.data
    localStorage.setItem('react-info', res.data) // 数据持久化
  }

  delInfo() {
    this.userInfo = {}
    localStorage.removeItem('react-info')
  }
}

export default User
